<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\model\Materials;
use app\common\model\Articles;
class Article extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function detail($article_id=null)
    {
    	$row = Materials::get($article_id);
    	if(empty($row)){
    		$this->error('数据不存在');
    	}
    	$wechat = db('wechats')->where('id',$row['wechat_id'])->find();
    	$row['content'] = preg_replace("/http:\/\/mmbiz.qpic.cn/i", url('showimg')."?url=http:\/\/mmbiz.qpic.cn", $row['content']);
    	$this->assign('row',$row);
    	$this->assign('wechat',$wechat);
        return $this->view->fetch();
    }
    public function showimg($url=null){
    	header('content_type:image/jpeg');
    	$url = preg_replace("/\\\\/i", '', $url);
    	echo file_get_contents($url);
    }

    public function show($id=null){
        $row = Articles::get($id);
        if(empty($row)){
            $this->error('数据不存在');
        }
        $this->assign('row',$row);
        return $this->view->fetch();
    }

}
